home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
crit.arc
/
CRIT.DOC
< prev
next >
Wrap
Text File
|
1986-12-01
|
4KB
|
132 lines
CRIT (2) Critical Error Handler CRIT (2)
CRITICAL
critical error handler routines for Microsoft C (et al)
SYNOPSIS
int setup_crit();
void restore_crit();
DESCRIPTION
These two functions implement a simple critical error
handler for Microsoft C. The setup_crit function works much
like the standard library's setjmp function - when it is
called initially, it returns 0. When a critical error
occurs, control is passed to the point where setup_crit was
called, and the function appears to return -1.
If a critical error occurs, the default DOS handler is
called, which will display the 'ABORT, RETRY, IGNORE'
message and wait for a key to be struck. If retry or ignore
are selected, then DOS does whatever it is it supposed to do
in that situation. If, however, the user selects abort,
then control is returned to your program at the point where
the call to setup_crit was made.
The whole rationale for these functions is for your program
to be able to catch fatal errors and deal with them
relatively gracefully. Unless they are used, DOS will
unceremoniously abort your program, leaving you with
dangling files and interrupt vectors.
The restore_crit function restores the default DOS critical
error handler. It is not necessary to call restore_crit
when your program terminates, as DOS restores the critical
error vector out of your program segment prefix. It will
allow you to turn off catching of critical errors.
CAVEATS
You may call setup_crit repeatedly without calling
restore_crit - an interlock is used so that garbage isn't
put into the critical error interrupt vector. However, each
call to setup_crit overwrites the context saved by previous
calls, so they do not nest.
EXAMPLES
The following example calls setup_crit to catch critical
errors. It then tries to open a file on drive A:. If you've
left the drive door open or have an unformatted diskette in
A:, the critical error will cause a return to the point
where setup_crit is called.
-1-
CRIT (2) Critical Error Handler CRIT (2)
#include <stdio.h>
main(argc,argv)
int argc;
char **argv;
{
FILE *foo = NULL;
static char fnamebuf[65];
/* attempt to open the file specified by the first command line
** argument
*/
sprintf(fnamebuf,"A:%s",argv[1]); /* build the file name */
for (;foo == NULL;)
{
if (-1 == setup_crit()) /* set up error handler */
{
/* if an error occurs, you will end up here */
fprintf(stderr,
"Check to make sure a valid disk is drive A:\n");
fprintf(stderr,"and that the drive door is closed\n");
fprintf(stderr,"Hit return to continue\n");
getchar();
}
foo = fopen(fnamebuf,"r");
}
restore_crit(); /* turn off critical error handling */
}
FILES
testcrit.c, crit.asm
RETURN VALUE
setup_crit returns 0 when invoked to set up critical error
catching, and -1 when a critical error occurs.
SEE ALSO
setjmp,longjmp
NOTES
These functions were written by
Kent Williams
722 Rundell
Iowa City IA 52240
(319)338-6053
They may be used freely, provided proper credit is given to
their author. They may be freely distributed, so long as
all components of this package (crit.asm testcrit.c and
crit.doc) are included, and no charge be made beyond a
nominal fee for duplication.
-2-